package com.wx.web;

import com.wx.service.WxCheckSignatureService;
import com.wx.utils.CheckUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author DKH
 * @version 1.0.0
 * @ClassName WxController.java
 * @Description TODO
 * @createTime 2021年11月10日 15:12:00
 */
@RestController
@RequestMapping("/wx")
public class WxController {

    @Autowired
    private WxCheckSignatureService wxCheckSignatureService;
    /**
     * 验证
     */
    @GetMapping("/login")
    public String auth(String signature,String timestamp,String nonce,String echostr) {
        if(CheckUtil.checkSignature(signature, timestamp, nonce)) {
            return echostr;
        }
        return null;
    }

    @PostMapping("/login")
    public String login(HttpServletRequest request,HttpServletResponse response) {
        return wxCheckSignatureService.messageHandle(request, response);
    }

}
